<?php

/**
 * User form.
 *
 * @package    myarticles
 * @subpackage form
 * @author     Apul Gupta<apulmca2k4@gmail.com>
 */
class UserForm extends BaseUserForm
{
  public function configure()
  {
      unset($this['meta_title'],$this['role_id'], $this['last_login'], $this['created_at'], $this['updated_at'], $this['token'], $this['is_active']);

      $this->widgetSchema['url_slug']->setLabel('User Name');
      if($this->getObject()->getPhoto()!=null)
      {
      $this->widgetSchema['photo']        = new sfWidgetFormInputFileEditable(
                  array(
                      'label'    => 'Photo',
                      'file_src' => '/images/user-photo/'.$this->getObject()->getPhoto(),
                      'is_image' => false,
                      'template' => '<div>%input%- <a href="http://'.$_SERVER['HTTP_HOST'].'%file%" target="_blank">Old Image</a></div>'
                  )
                  );
      }
      else
      {
          $this->widgetSchema['photo'] = new sfWidgetFormInputFile();
      }
      $this->widgetSchema['meta_keyword'] = new sfWidgetFormTextarea();
      $this->widgetSchema['meta_description'] = new sfWidgetFormTextarea();
      
      $this->validatorSchema['web_url']   = new sfValidatorUrl(array('required'=>false));

      $this->validatorSchema['photo']     = new sfValidatorFile(array(
          'path' => sfConfig::get('sf_web_dir').'/images/user-photo',
          'mime_types' => 'web_images', 'max_size' => 100000, 'required' => false));
      
      $this->validatorSchema['email_id']  = new sfValidatorEmail();
      
      $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
      $this->validatorSchema['display_name']->setOption('required', true);
      $this->validatorSchema->setPostValidator(
                              new sfValidatorPropelUnique(
                                      array('model' => 'user', 'column' => 'url_slug'),
                                      array('invalid' => 'Username already exist!')));
      
      $this->widgetSchema->setNameFormat('user[%s]');
  }
}